home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1997 August / Macworld (1997-08).dmg / Serious Demos / Crimson Demo / Crimson Basic Manual / Crimson Basic Manual.rsrc / TEXT_1600_Language Reference Part 2.txt < prev    next >
Text File  |  1997-06-17  |  15KB  |  612 lines

  1. I    
  2. If
  3.  
  4. The IF statement sets conditions which determine program flow.
  5.  
  6. Syntax
  7.         IF <logical expression> [THEN]
  8.             <statement(s)>
  9.         [ELSE
  10.             <statement(s)>]
  11.         ENDIF
  12.  
  13. Example
  14.         IF A>B
  15.             Print "Hello"
  16.         ENDIF
  17.  
  18.         IF Myfunc(Z) THEN
  19.             A=1
  20.         ELSE
  21.             A=2
  22.         ENDIF
  23.  
  24. Inc
  25.  
  26. The INC command increments the value of an integer variable. This is equivalent to but much faster than var=var+1.
  27.  
  28. Syntax
  29.         INC <integer variable name>
  30.  
  31. Example
  32.         INC A
  33.  
  34. Initmenu
  35.  
  36. The Initmenu command creates a Menu Bar for the application and adds an 'Apple" menu.
  37. The Initmenu command must be executed before any other menu commands will function.
  38.  
  39. Syntax
  40.         INITMENU
  41.  
  42. Example
  43.         InitMenu
  44.  
  45. Inkey
  46.  
  47. The INKEY statement waits for a character to be pressed (when the console is open) and then resumes program execution.
  48.  
  49. Syntax
  50.         INKEY
  51.  
  52. Input
  53.  
  54. The INPUT statement allows a user to enter keyboard data into the Console and assign it to a program variable.
  55.  
  56. Syntax
  57.         INPUT <variable name>
  58.  
  59. Example
  60.         INPUT Mystring
  61.         INPUT Myint
  62.  
  63. Note
  64. The variable to which data is Input must be of type Integer,String or Float.
  65. Hexadecimal numbers may be Input in the form &H12FA or &FFFF.
  66.  
  67. Inputbox(
  68.  
  69. The Inputbox function displays a Modal Dialog box on the screen with the given prompt displayed within it. The user may enter string data into the InputBox and this is returned to the program once the OK button is pressed.
  70.  
  71. Syntax
  72.         INPUTBOX(<string expression>)
  73.  
  74. Example
  75.         Response=InputBox("Enter a string")
  76.  
  77. Input#
  78.  
  79. This statement reads data from the file specified by the file_number parameter. The data read must be of the Integer or String data types.
  80.  
  81. Syntax
  82.         INPUT #<file_number>,<variable list>
  83.  
  84. Example
  85.         INPUT #1,Myint,Mystr
  86.  
  87. Note
  88. Input# is normally used to read data written with the WRITE# statement.
  89.  
  90. Instr(
  91.  
  92. Searches to see if a character string is present within another string and returns its position.
  93.  
  94. Syntax
  95.         INSTR(<string expression>,<string expression>)
  96.  
  97. Example
  98.         A=INSTR("ABCDEF","CD")   .. would set A to 3.
  99.  
  100. Note
  101.         If the string is not present then zero is returned.
  102.  
  103. Integer(
  104.  
  105. The INTEGER( function performs type conversion into INTEGER datatype format.
  106.  
  107. Syntax
  108.             INTEGER(<expression>)
  109.  
  110. Example
  111.             I=INTEGER(W)
  112.  
  113. Note
  114.             If the <expression> yields an Byte or Word result then it is extended
  115.             to 32 bits by the INTEGER( function.
  116.             If the <expression> yields a Float result then it is truncated to an Integer.
  117.             If the <expression> yields a Char,  Str255 or String result then
  118.             the result will be equivalent to the numeric value of the string.
  119.  
  120. L    
  121. Left(
  122.  
  123. This function returns a string made up of the leftmost n characters of a string expression.
  124.  
  125. Syntax
  126.         LEFT(<string expression>,<length expression>)
  127.  
  128. Example
  129.         S=LEFT("ABCDEF",3)           .. S is set to "ABC"
  130.         S=LEFT ("AB",6)                  .. S is set to "AB"
  131.  
  132. Len(
  133.  
  134. The LEN( function returns the length (number of characters) of a String type variable. 
  135.  
  136. Syntax
  137.         LEN(<string expression>)
  138.  
  139. Example
  140.         I=LEN("ABCD")                     .. I is set to 4
  141.  
  142. Let
  143.  
  144. The LET statement assigns the value of an expression to a variable.
  145.  
  146. Syntax
  147.         [LET] <variable name> = <expression>
  148.  
  149. Note
  150. The LET keyword is optional
  151.  
  152. Example
  153.         LET A=2
  154.         MyAry(I)=Val(S)
  155.  
  156. Line Input#
  157.  
  158. The LINE INPUT# statement reads a string of characters from a file, terminated by a carriage return, and assigns them to a string variable.
  159.  
  160. Syntax
  161.         LINE INPUT #<file_number>,<string variable>
  162.  
  163. Example
  164.         LINE INPUT #1,Mystr
  165.  
  166. Note
  167. LINE INPUT# may be used to read data from a standard TEXT file or from a file written using the PRINT# statement.
  168.  
  169. Local
  170.  
  171. The Local statement declares variables which are local in scope. The Local statement may only be declared within a FUNCTION or PROCEDURE construct.
  172.  
  173. Syntax
  174.         LOCAL <variable name> AS <variable type> [<string length>] [<dimensions>]
  175.  
  176. Example
  177.         LOCAL F AS FLOAT.
  178. See GLOBAL for other examples.
  179.  
  180. Lpeek(
  181.  
  182. The Lpeek (Long Peek) function returns the 32 bit value stored in a given memory location.
  183.  
  184. Syntax
  185.         LPEEK(<integer value>)
  186.  
  187. Example
  188.         Myint=LPEEK(10538)
  189.  
  190. Lpoke
  191.  
  192. The Lpoke command places a 32 bit value into a given memory location. Use with care.
  193.  
  194. Syntax
  195.         LPOKE ,<integer memory address>,<integer value>
  196.  
  197. Example
  198.         LPOKE 10538,A
  199.  
  200. M    
  201. Mid(
  202.  
  203. This function returns <length expression> characters from <string expression> starting at the <start expression> character.
  204.  
  205. Syntax
  206.         MID(<string expression>,<start expression>,<length expression>)
  207.  
  208. Example
  209.  
  210.         S1=MID("ABCDEF",2,3)           .. S1 is set to "BCD"
  211.         S2=MID("ABC",3,6)                 .. S2 is set to "C"
  212.  
  213. Msgbox(
  214.  
  215. The MsgBox function displays a message to the user inside a Modal Dialog Box. 
  216.  
  217. Syntax
  218.         MSGBOX(<string expression>,<string expression>,<string expression>)
  219.  
  220. Example
  221.         WhichButton=MsgBox("Are you shure","Yes","No")
  222.  
  223. Note
  224. The first parameter specifies the string which will appear in the Message Box.
  225. The second parameter specifies the caption on the default button within the Message Box.
  226. The third parameter specifies the caption on the second button within the Message Box. If a null string is supplied to this parameter then the second button will be invisible.
  227. The value returned from MsgBox is an Integer which specifies which button was pressed, 1 for the default button, and 2 for the second button.
  228.  
  229. N    
  230. Next
  231.  
  232. The Next statement terminates a FOR / NEXT loop.
  233.  
  234. Syntax
  235.         NEXT <variable name>
  236.  
  237. Example
  238. See FOR.
  239.  
  240. Not
  241.  
  242. Performs a logical NOT upon a conditional expression.
  243.  
  244. Syntax
  245.         NOT <conditional expression>
  246.  
  247. Example
  248.         If NOT A>B THEN
  249.  
  250. O    
  251. Open
  252.  
  253. Opens a disk file.
  254.  
  255. Syntax
  256.         OPEN <filespec> [FOR <mode>] AS [#]<file number> [LEN=<record length>]
  257.  
  258. Example
  259.         OPEN "Myfile" FOR OUTPUT AS #1
  260.         OPEN "Randfile" FOR RANDOM As #2 LEN=10
  261.  
  262. Note
  263. The filespec may be given as a single filename (which must exist in the current folder) 
  264. or as a full path name.
  265. The following modes are permissible :
  266.         INPUT          for reading only, this is the default.
  267.         OUTPUT       for writing only, an existing file of the same name will be 
  268.                            overwritten if it exists.
  269.         APPEND       appends to an existing file. The file must exist.
  270.         RANDOM       for random input/output. See PUT and GET for examples of its use.
  271. The file number may be any integer and is used to uniquely identify the open file.
  272. The LEN parameter applies only to files opened in RANDOM mode. It specifies the length of each record.
  273. When unsucessful, the OPEN command sets the ERR variable.
  274.  
  275. Open Console
  276.  
  277. Opens the console window.
  278.  
  279. Syntax
  280.         OPEN CONSOLE
  281.  
  282. Note
  283. The console is automatically opened whenever something is written to the console using the PRINT statement.
  284.  
  285. Or
  286.  
  287. Performs a logical OR on 2 conditional expressions or a bitwise OR on two integer expressions.
  288.  
  289. Syntax
  290.         <conditional expression> OR <conditional expression>
  291.         <integer expression> OR <integer expression>
  292.  
  293. Example
  294.         IF A>B OR C>D
  295.         B=C AND &H00FF
  296.  
  297. P    
  298. Peek(
  299.  
  300. The Peek function returns the 8 bit value stored in a given memory location.
  301.  
  302. Syntax
  303.         PEEK(<integer value>)
  304.  
  305. Example
  306.         Myint=PEEK(10538)
  307.  
  308. Poke
  309.  
  310. The Poke command places a 8 bit value into a given memory location. Use with care.
  311.  
  312. Syntax
  313.         POKE ,<integer memory address>,<integer value>
  314.  
  315. Example
  316.         POKE 10538,A
  317.  
  318. Parameter
  319.  
  320. The Parameter statement defines parameters passed into a Function or Procedure.
  321.  
  322. Syntax
  323.         PARAMETER <parameter name> AS <data type> [BYREF]
  324.  
  325. Example
  326.         PROCEDURE Myproc(A,B,C)
  327.         PARAMETER A AS INTEGER
  328.         PARAMETER B AS STRING
  329.         PARAMETER C AS INTEGER BYREF
  330.  
  331. Note
  332. When a parameter is marked as BYREF, it must also be declared as BYREF( in the calling statement. A BYREF parameter may have its value changed during execution of the function / procedure. All other parameters may not.
  333.  
  334.         Do Myproc(X,BYREF(Y))
  335.         ........
  336.         ........
  337.         FUNCTION Myproc(P,Q) RETURNING INTEGER
  338.         PARAMETER P AS INTEGER
  339.         PARAMETER Q AS STRING BYREF
  340.             Q="Changed String"
  341.         RETURN 99
  342.  
  343. Precision
  344.  
  345. The Precision command sets the number of digits, after the decimal point, which will be present when a Float type variable is converted to a String, for example to be used in a Print statement, or explicitly converted using the Str( function.
  346.  
  347. Syntax
  348.         PRECISION <integer expression>
  349.  
  350. Example
  351.         Precision 4
  352.         MyFloat=1.44444444
  353.         Print MyFloat
  354.  
  355.         .. will print 1.4444
  356.  
  357. Note
  358. The default value for Precision is 2.
  359.  
  360. Print
  361.  
  362. The print statement outputs data to the console.
  363.  
  364. Syntax
  365.         PRINT <expression>[;][,][<expression>] ...
  366.  
  367. Example
  368.         PRINT A
  369.         PRINT B;C,D
  370.  
  371. Note
  372. Placing a semi-colon after an expression will suppress the automatic newline which is the default for the Print command. A comma will insert a Tab character.
  373.  
  374. Print#
  375.  
  376. The PRINT# statement outputs character data to a disk file.
  377.  
  378. Syntax
  379.         PRINT #<file_number>,<expression>[;][,][<expression>] ...
  380.  
  381. Example
  382.         Print #1,Mystr
  383.         Print #2,Myint;Mystr,Myint2
  384.  
  385. Procedure
  386.  
  387. The Procedure statement declares the start of a user defined procedure.
  388.  
  389. Syntax
  390.         PROCEDURE <name>(<parameter list>)
  391.  
  392. Example
  393.  
  394.         PROCEDURE Myproc(A,B,C) 
  395.  
  396.         Declares the start of a procedure, Myproc, which receives 3 parameters (defined
  397.         by the PARAMETER statement).
  398.  
  399. Put
  400.  
  401. The PUT statement will write a record to a file which has been opened in RANDOM mode.
  402.  
  403. Syntax
  404.         PUT #<file_number>,<record_number>,<variable_name>
  405.  
  406. Example
  407.         PUT #1,123,Mystr
  408.  
  409. Note
  410. The variable from which the data is written may be a STRING or a STRUCTURE type.
  411. Take care to specify the record_number correctly as the file will be extended to occupy the highest record_number written.
  412.  
  413. R    
  414.  
  415. Redim
  416.  
  417. The Redim statement changes the size of an array to have dimensions which are greater or smaller than the original.
  418.  
  419. Syntax
  420.         REDIM <array name> AS <integer expression>
  421.  
  422. Example
  423.         REDIM Myarray As 50
  424.  
  425. Note
  426. Redim changes the size of the last array dimension declared. ie.
  427.         GLOBAL Myarray AS Integer(3,10)   ... followed by
  428.         REDIM Myarray As 20 ..
  429.         would result in an array of size (3,20) will all data preserved.
  430.  
  431. Repeat
  432.  
  433. The section of the program between Repeat and Until is executed until the conditional expression following the Until command is fulfilled.
  434.  
  435. Syntax
  436.         REPEAT
  437.  
  438. Example
  439.         I=0
  440.         REPEAT
  441.             INC I
  442.             PRINT I
  443.         UNTIL I=10         ... will print the numbers 1 through 10.
  444.  
  445. Return
  446.  
  447. Specifies a Return from either a Procedure or a Function.
  448.  
  449. Syntax (Procedure)
  450.         RETURN
  451.  
  452. Syntax(Function)
  453.         RETURN <expression>
  454.  
  455. Note
  456. The expression following the RETURN statement for a function must result in the same data type as specified in the RETURNING parameter in the Function statement.
  457.  
  458.  
  459. Right(
  460.  
  461. This function returns a string made up of the rightmost n characters of a string expression.
  462.  
  463. Syntax
  464.         RIGHT(<string expression>,<length expression>)
  465.  
  466. Example
  467.         S=RIGHT("ABCDEF",3)         .. S is set to "DEF"
  468.         S=RIGHT ("AB",6)                .. S is set to "AB"
  469.  
  470. S    
  471. Sgn(
  472.  
  473. The SGN function determines whether the result of an expression is negative, zero or positive.
  474.  
  475. Syntax
  476.         SGN(<numeric expression>)
  477.  
  478. Example
  479.         PRINT SGN(-6)            .. prints -1
  480.         PRINT SGN(0)              .. prints 0
  481.         PRINT SGN(99.4)         .. prints 1
  482.  
  483. Str(
  484.  
  485. Converts an Integer or Float data type into a string.
  486.  
  487. Syntax
  488.         STR(<numeric expression>)
  489.  
  490. Example
  491.         PRINT STR(123)     ... would print the string "123"
  492.  
  493. String(
  494.  
  495. The String function converts data from other data types into the String data type.
  496.  
  497. Syntax
  498.         STRING(<expression>)
  499.  
  500. Example
  501.         I=STRING(A+B)
  502.  
  503. Note
  504. If the expression yields a Byte result then the resulting string will contain the ascii representation of the value of the Byte.
  505. If the expression yields A Word ,Integer or Float result then the resulting string will contain the string representation of the expression. See STR(.
  506. If the expression yields a Char or Str255 result then this will be converted to a String data type.
  507.  
  508. Str255(
  509.  
  510. The Str255 function converts data from other data types into the Pascal String data type.
  511.  
  512. Syntax
  513.         STR255(<expression>)
  514.  
  515. Example
  516.         I=STR255(A+B)
  517.  
  518. Note
  519. If the expression yields a Byte result then the resulting Pascal String will contain the ascii representation of the value of the Byte.
  520. If the expression yields A Word, Integer or Float result then the resulting Pascal String will contain the string representation of the expression.
  521. If the expression yields a Char or String result then this will be converted to a Pascal String data type.
  522.  
  523. Sub
  524.  
  525. The SUB command performs the subtraction function on two operators.
  526.  
  527. Syntax
  528.             SUB <integer variable name>,<numeric expression>
  529.  
  530. Example
  531.             SUB Myvar,10    -- Subtracts 10 from variable Myvar
  532.             SUB A,B             -- Subtracts variable B from A
  533.  
  534. T    
  535. True
  536.  
  537. True, when used in an expression yields a result of -1 and is used as a documentation aid.
  538.  
  539. Syntax
  540.         TRUE
  541.  
  542. Example
  543.         If A=True
  544. U    
  545. Until
  546.  
  547. The Until statement terminates a REPEAT/UNTIL loop.
  548.  
  549. Syntax
  550.         UNTIL <expression>
  551.  
  552. Example
  553. See Repeat.
  554.  
  555. Upper(
  556.  
  557. The Upper function translates a String type expression into Upper Case.
  558.  
  559. Syntax
  560.         UPPER(<string expression>)
  561.  
  562. Example
  563.         S1=UPPER("abc123Xyz)      ... sets S1 to "ABC123XYZ"
  564.  
  565. V    
  566. Varptr(
  567.  
  568. The Varptr function returns the address in memory of a given variable.
  569.  
  570. Syntax
  571.         VARPTR(<variable name>)
  572.  
  573. Example
  574.         Myint=VARPTR(Mystr)
  575.  
  576. Val(
  577.  
  578. The Val function returns the integer value of the leading portion of a string expression.
  579.  
  580. Syntax
  581.         VAL(<string expression>)
  582.  
  583. Example
  584.         Myint=VAL(Mystr)
  585.  
  586. Note
  587. Use FLOAT to convert a string into a Floating Point value.
  588.  
  589. Val?(
  590.  
  591. The Val? functions returns the number of characters which would make up the Integer portion of a string expression.
  592.  
  593. Syntax
  594.         VAL?(<string expression>)
  595.  
  596. Example
  597.         I= Val?("-123XYZ")   .. would set I to 4 (-123)
  598.  
  599. W    
  600. Write#
  601.  
  602. This statement writes the value of program variables to a disk file.
  603.  
  604. Syntax
  605.         WRITE #<file_number>,<expression list>
  606.  
  607. Example
  608.         Write #1,Myint,Mystring
  609.  
  610. Note
  611. Write# is normally used to write data to be read with the INPUT# statement.
  612.